using System;
using System.IO;
using System.Text;

namespace EventMsg;

public static class LoggerWrite
{
	public static void Error(string message, Exception ex)
	{
		try
		{
			StringBuilder error = new StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n" + message + "\r\n");
			if (ex != null)
			{
				error.Append(ex.Message + Environment.NewLine);
				error.Append(ex.StackTrace + Environment.NewLine);
				if (ex.InnerException != null)
				{
					error.Append(ex.InnerException.Message + Environment.NewLine);
				}
			}
			if (!Directory.Exists("logs"))
			{
				Directory.CreateDirectory("logs");
			}
			string today = DateTime.Today.ToString("yyyy-MM-dd");
			if (!Directory.Exists("logs" + Path.DirectorySeparatorChar + today))
			{
				Directory.CreateDirectory("logs" + Path.DirectorySeparatorChar + today);
			}
			int hour = DateTime.Now.Hour;
			using StreamWriter file = new StreamWriter("logs" + Path.DirectorySeparatorChar + today + Path.DirectorySeparatorChar + "error2_" + hour + ".txt", append: true);
			file.WriteLine(error);
		}
		catch
		{
		}
	}

	public static void Debug(string message)
	{
		try
		{
			StringBuilder error = new StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n" + message + "\r\n");
			if (!Directory.Exists("logs"))
			{
				Directory.CreateDirectory("logs");
			}
			string today = DateTime.Today.ToString("yyyy-MM-dd");
			if (!Directory.Exists("logs" + Path.DirectorySeparatorChar + today))
			{
				Directory.CreateDirectory("logs" + Path.DirectorySeparatorChar + today);
			}
			int hour = DateTime.Now.Hour;
			using StreamWriter file = new StreamWriter("logs" + Path.DirectorySeparatorChar + today + Path.DirectorySeparatorChar + "debug2_" + hour + ".txt", append: true);
			file.WriteLine(error);
		}
		catch
		{
		}
	}

	public static void Info(string message)
	{
		try
		{
			StringBuilder error = new StringBuilder(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n" + message + "\r\n");
			if (!Directory.Exists("logs"))
			{
				Directory.CreateDirectory("logs");
			}
			string today = DateTime.Today.ToString("yyyy-MM-dd");
			if (!Directory.Exists("logs" + Path.DirectorySeparatorChar + today))
			{
				Directory.CreateDirectory("logs" + Path.DirectorySeparatorChar + today);
			}
			int hour = DateTime.Now.Hour;
			using StreamWriter file = new StreamWriter("logs" + Path.DirectorySeparatorChar + today + Path.DirectorySeparatorChar + "info2_" + hour + ".txt", append: true);
			file.WriteLine(error);
		}
		catch
		{
		}
	}
}
